import io
import pickle
import tkinter as tk
from tkinter import ttk, filedialog
import time
import tkinter.messagebox

import keyboard
import pyscreeze
import win32gui
import win32con
from pymouse import PyMouse
from win32gui import *
import cv2
import numpy
from PIL import Image, ImageGrab
import _thread
import os


# ##主窗口设置##
# 建立一个主窗口
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
# 窗口标题
root.title("开发者工具")
# 窗口锁定
# "{0}x{1}".format(screen_width, screen_height
root.geometry("+{0}+{1}".format(int(screen_width/2.2), int(screen_height/3)))
# 防止窗口拉扯
root.resizable(0, 0)
# 窗口置顶
# root.wm_attributes('-topmost', 1)


# ##变量定义##
hwnd = win32gui.FindWindow(None, None)

operation_values = ["点击", "拖拽", "输入文本"]
click_values = ["点击识别图片中心", "点击选择坐标"]
input_values = ["点击坐标后输入文本", "输入文本后点击坐标", "只输入文本"]
resolving_power_values = ["540x960", "720x1280", "960x540", "1280x720", "800X600"]
operation_list = []  # 储存操作
window_values = []
path = ""
window_text = tk.StringVar()
monitor_text = tk.StringVar()
resolving_power_text = tk.StringVar()
screen_text = tk.StringVar()
main_text = tk.StringVar()
subtask_text = tk.StringVar()
desc_text = tk.StringVar()
operation_text = tk.StringVar()
click_text = tk.StringVar()
translate_text = tk.StringVar()
drag_text = tk.StringVar()
content_text = tk.StringVar()
input_text = tk.StringVar()
delay_text = tk.StringVar()
threshold_text = tk.StringVar()
cut_img = 0
# 截图变量
img_cut = ImageGrab.grab()
# point1 = (0, 0)
# point2 = (0, 0)
# x = 0
# y = 0
# 变量初始值
screen_text.set("{0}x{1}".format(screen_width, screen_height))
main_text.set("倩女幽魂")
subtask_text.set("登录游戏")
desc_text.set("选区")
operation_text.set("请选择")
click_text.set("点击识别图片中心")
translate_text.set("0,0")
drag_text.set("x1,y1 x2,y2")
content_text.set("这是我输入的内容")
input_text.set("请选择")
window_text.set("请选择")
delay_text.set("1000")
threshold_text.set("0.95")
xstart = 0
ystart = 0
xend = 0
yend = 0
set_root = None
add_root = None

# 操作类


class Click:
    def __init__(self, translate, delay_time):
        self.operation_id = len(operation_list)
        self.translate = translate
        self.delay_time = delay_time
        operation_list.append(self)


class Drag:
    def __init__(self, translate_front, translate_behind, delay_time):
        self.operation_id = len(operation_list)
        self.translate_pre = translate_front
        self.translate_behind = translate_behind
        self.delay_time = delay_time
        operation_list.append(self)


class Input:
    def __init__(self, text, delay_time):
        self.operation_id = len(operation_list)
        self.text = text
        self.delay_time = delay_time
        operation_list.append(self)


# ##方法实现##
def add_task():
    global add_root
    add_root = tk.Toplevel()
    add_root.title("id:" + str(len(operation_list)))
    add_root.geometry("+{0}+{1}".format(int(screen_width/2.2), int(screen_height/3)))
    add_root.wm_attributes('-topmost', 1)
    # 函数

    def save():
        if operation_text.get() == "点击":
            screen_text.set("id:" + str(len(operation_list)) + "临时保存至内存")
            Click(translate_text.get(), delay_text.get())
            add_root.destroy()
            root.update()
        if operation_text.get() == "拖拽":
            screen_text.set("id:" + str(len(operation_list)) + "临时保存至内存")
            Drag(drag_text.get().split(" ")[0], drag_text.get().split(" ")[1], delay_text.get())
            add_root.destroy()
            root.update()
        if operation_text.get() == "输入文本":
            screen_text.set("id:" + str(len(operation_list)) + "临时保存至内存")
            Input(input_text.get(), delay_text.get())
            add_root.destroy()
            root.update()
        if operation_text.get() == "请选择操作":
            warn_Label = tk.Label(add_root, text="警告：请选择操作！")
            warn_Label.config(fg="red")
            warn_Label.grid(row=6, columnspan=2, ipadx=5, ipady=5)
            add_root.update()
        if debug:
            for op in operation_list:
                print('\n'.join(['%s:%s' % item for item in op.__dict__.items()]))
                print("--------------------")
            print("-----------------------")

    def update_add_root(event):
        if operation_text.get() == "点击":
            translate_Entry = tk.Entry(add_root, textvariable=translate_text, state='normal')
            drag_Entry = tk.Entry(add_root, textvariable=drag_text, state='readonly')
            input_Entry = tk.Entry(add_root, textvariable=input_text, state='readonly')
            translate_Entry.grid(row=1, column=1, ipadx=5, ipady=5)
            drag_Entry.grid(row=2, column=1, ipadx=5, ipady=5)
            input_Entry.grid(row=3, column=1, ipadx=5, ipady=5)
            delay_Entry = tk.Entry(add_root, textvariable=delay_text, state='normal')
            delay_Entry.grid(row=4, column=1, ipadx=5, ipady=5)
            delay_text.set("2000")
            translate_text.set("0,0")
            drag_text.set("无法进行操作")
            input_text.set("无法进行操作")
            warn_Label = tk.Label(add_root, text="提示：0,0为点击当前坐标")
            warn_Label.config(fg="blue")
            warn_Label.grid(row=6, columnspan=2, ipadx=5, ipady=5)
            add_root.update()
        if operation_text.get() == "拖拽":
            translate_Entry = tk.Entry(add_root, textvariable=translate_text, state='readonly')
            drag_Entry = tk.Entry(add_root, textvariable=drag_text, state='normal')
            input_Entry = tk.Entry(add_root, textvariable=input_text, state='readonly')
            translate_Entry.grid(row=1, column=1, ipadx=5, ipady=5)
            drag_Entry.grid(row=2, column=1, ipadx=5, ipady=5)
            input_Entry.grid(row=3, column=1, ipadx=5, ipady=5)
            delay_Entry = tk.Entry(add_root, textvariable=delay_text, state='normal')
            delay_Entry.grid(row=4, column=1, ipadx=5, ipady=5)
            delay_text.set("2000")
            translate_text.set("无法进行操作")
            drag_text.set("0,0 0,0")
            input_text.set("无法进行操作")
            warn_Label = tk.Label(add_root, text="提示：输入拖拽前后的坐标哦")
            warn_Label.config(fg="blue")
            warn_Label.grid(row=6, columnspan=2, ipadx=5, ipady=5)
            add_root.update()
        if operation_text.get() == "输入文本":
            translate_Entry = tk.Entry(add_root, textvariable=translate_text, state='readonly')
            drag_Entry = tk.Entry(add_root, textvariable=drag_text, state='readonly')
            input_Entry = tk.Entry(add_root, textvariable=input_text, state='normal')
            translate_Entry.grid(row=1, column=1, ipadx=5, ipady=5)
            drag_Entry.grid(row=2, column=1, ipadx=5, ipady=5)
            input_Entry.grid(row=3, column=1, ipadx=5, ipady=5)
            delay_Entry = tk.Entry(add_root, textvariable=delay_text, state='normal')
            delay_Entry.grid(row=4, column=1, ipadx=5, ipady=5)
            delay_text.set("2000")
            translate_text.set("无法进行操作")
            drag_text.set("无法进行操作")
            input_text.set("输入文本")
            warn_Label = tk.Label(add_root, text="提示：这个只是键盘输入文本哦")
            warn_Label.config(fg="blue")
            warn_Label.grid(row=6, columnspan=2, ipadx=5, ipady=5)
            add_root.update()
    # 定义变量

    # 组件
    operation_Label = tk.Label(add_root, text="操作")
    operation_Combobox = ttk.Combobox(add_root, state='readonly', values=operation_values, width=17,
                                      textvariable=operation_text)
    operation_Combobox.bind('<<ComboboxSelected>>', update_add_root)
    operation_text.set("请选择操作")
    translate_Label = tk.Label(add_root, text="点击坐标")
    translate_Entry = tk.Entry(add_root, textvariable=translate_text, state='readonly')
    translate_text.set("无法进行操作")
    drag_Label = tk.Label(add_root, text="拖拽")
    drag_Entry = tk.Entry(add_root, textvariable=drag_text, state='readonly')
    drag_text.set("无法进行操作")
    input_Label = tk.Label(add_root, text="输入文本")
    input_Entry = tk.Entry(add_root, textvariable=input_text, state='readonly')
    input_text.set("无法进行操作")
    delay_Label = tk.Label(add_root, text="延迟毫秒")
    delay_Entry = tk.Entry(add_root, textvariable=delay_text, state='readonly')
    delay_text.set("无法进行操作")
    save_Button = tk.Button(add_root, text="保存", command=save)

    operation_Label.grid(row=0, column=0, ipadx=5, ipady=5)
    operation_Combobox.grid(row=0, column=1, ipadx=5, ipady=5)
    translate_Label.grid(row=1, column=0, ipadx=5, ipady=5)
    translate_Entry.grid(row=1, column=1, ipadx=5, ipady=5)
    drag_Label.grid(row=2, column=0, ipadx=5, ipady=5)
    drag_Entry.grid(row=2, column=1, ipadx=5, ipady=5)
    input_Label.grid(row=3, column=0, ipadx=5, ipady=5)
    input_Entry.grid(row=3, column=1, ipadx=5, ipady=5)
    delay_Label.grid(row=4, column=0, ipadx=5, ipady=5)
    delay_Entry.grid(row=4, column=1, ipadx=5, ipady=5)
    save_Button.grid(row=5, columnspan=2, ipadx=5, ipady=5)
    add_root.mainloop()


def set_windows():
    global window_values
    global set_root
    set_root = tk.Toplevel()
    set_root.title("设置")
    set_root.geometry("+{0}+{1}".format(int(screen_width/2.2), int(screen_height/3)))
    set_root.wm_attributes('-topmost', 1)
    # 获取窗口
    window_values = get_list_lpWindowName()
    window_Label = tk.Label(set_root, text="选择窗口")
    windows_Combobox = ttk.Combobox(set_root, state='readonly', values=window_values, width=17, textvariable=window_text)
    windows_Combobox.bind('<<ComboboxSelected>>', get_hwnd)
    # 移动窗口
    resolving_power_Label = tk.Label(set_root, text="选择分辨率")
    resolving_power_Combobox = ttk.Combobox(set_root, state='readonly', values=resolving_power_values, width=17,
                                            textvariable=resolving_power_text)
    resolving_power_Combobox.bind('<<ComboboxSelected>>', move_window)
    window_Label.grid(row=0, column=0)
    windows_Combobox.grid(row=0, column=1)
    resolving_power_Label.grid(row=1, column=0)
    resolving_power_Combobox.grid(row=1, column=1)
    set_root.mainloop()


def move_window(event):
    global hwnd
    global set_root
    win32gui.SetWindowPos(hwnd, win32con.HWND_NOTOPMOST, 0, 0, int(resolving_power_text.get().split("x")[0]),
                          int(resolving_power_text.get().split("x")[1]), win32con.SWP_SHOWWINDOW)
    set_root.destroy()


def get_hwnd(event):
    global hwnd
    hwnd = win32gui.FindWindow(None, window_text.get())


def get_list_lpWindowName():
    list_lpWindowName = []
    titles = set()

    def foo(hwnd, nouse):
        # 去掉下面这句就所有都输出了，但是我不需要那么多
        if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
            titles.add(GetWindowText(hwnd))

    EnumWindows(foo, 0)
    lt = [t for t in titles if t]
    lt.sort()
    for t in lt:
        list_lpWindowName.append(t)
    return list_lpWindowName


def show_img(img):
    img.show()


def cut_thread():
    global operation_list
    operation_list = []
    _thread.start_new_thread(cut, ())


def gray(img):
    # 灰度化处理
    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    return gray_img


def image_to_position(screen, template):
    image_x, image_y = template.shape[:2]
    result = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
    result_list = [max_val, max_loc, image_x, image_y]
    return result_list


def screeze():
    pyscreeze.screenshot("screen.jpg")


def next_set():
    global cut_img
    screeze()
    screen = gray(cv2.imread('screen.jpg'))
    # try:
    if debug:
        print(cut_img)
    if type(cut_img) is int:
        screen_text.set("请先截图！才能识别")
        root.update()
        return 0
    result_list = image_to_position(screen, gray(cut_img))


    # except Exception:
    #     screen_text.set("请先截图！才能识别")
    #     root.update()
    #     return 0
    print(result_list)
    max_loc = result_list[1]
    image_x = float(result_list[2])
    image_y = float(result_list[3])
    if float(result_list[0]) >= float(threshold_text.get()):
        tkinter.messagebox.askokcancel(title='识别结果', message='识别到物体\n识别率为：' + str(result_list[0]) + "坐标为：" +
                                        str(float(max_loc[0]) + image_y / 2) + "," + str(float(max_loc[1]) + image_x / 2))
    else:
        tkinter.messagebox.askokcancel(title='识别率', message='该阈值无法识别到物体\n识别率为：' + str(result_list[0]))


def cut():
    global img_cut
    img_cut = ImageGrab.grab()
    # # 灰度识别 COLOR_BGR2GRAY
    # # RGB COLOR_RGB2BGR
    img_cut = cv2.cvtColor(numpy.asarray(img_cut), cv2.COLOR_RGB2BGR)
    if "{0}x{1}".format(screen_width, screen_height) == "1920x1080":
        cv2.namedWindow('image')
    else:
        cv2.namedWindow('image', cv2.WINDOW_NORMAL)
    cv2.setMouseCallback('image', on_mouse)
    cv2.imshow('image', img_cut)
    cv2.waitKey(0)


def scrren_cut():
    global img_cut


def save_img(cut_img):
    global path
    path = os.path.join(os.getcwd(), "img")
    path = os.path.join(path, main_text.get())
    path = os.path.join(path, subtask_text.get())
    if not os.path.exists(path):  # 判断是否存在文件夹如果不存在则创建为文件夹
        os.makedirs(path)
    path = os.path.join(path, desc_text.get() + str(time.time()) + ".jpg")
    if debug:
        print(path)
    try:
        cv2.imencode('.jpg', cut_img)[1].tofile(path)
    except cv2.error:
        screen_text.set("截图取消")
        root.update()


def on_mouse(event, x, y, flags, param):
    global img_cut, point1, point2
    global cut_img
    print(param)
    img2 = img_cut.copy()
    if event == cv2.EVENT_LBUTTONDOWN:         # 左键点击
        point1 = (x, y)
        cv2.circle(img2, point1, 10, (0, 255, 0), 5)
        cv2.imshow('image', img2)
    elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON):               # 按住左键拖曳
        cv2.rectangle(img2, point1, (x, y), (255, 0, 0), 5)
        cv2.imshow('image', img2)
    elif event == cv2.EVENT_LBUTTONUP:         # 左键释放
        point2 = (x, y)
        cv2.rectangle(img2, point1, point2, (0, 0, 255), 5)
        cv2.imshow('image', img2)
        min_x = min(point1[0], point2[0])
        min_y = min(point1[1], point2[1])
        width = abs(point1[0] - point2[0])
        height = abs(point1[1] - point2[1])
        cut_img = img_cut[min_y:min_y+height, min_x:min_x+width]
        save_img(cut_img)
        cv2.destroyWindow("image")


def add(file, text):
    file = open(file, "a+b")
    if type(text) is bytes:
        file.write(text)
        if debug:
            print("追加：", text)
    file.close()


def complete():
    global path
    global operation_list
    if debug:
        print(operation_list)
    if len(operation_list) == 0:
        if tkinter.messagebox.askokcancel('提示', '没有任何操作，确定要保存吗？'):
            main_information = "__mainTask__".encode() + main_text.get().encode() + "__mainTask__".encode()
            sub_information = "__subTask__".encode() + subtask_text.get().encode() + "__subTask__".encode()
            desc_information = "__desc__".encode() + desc_text.get().encode() + "__desc__".encode()
            threshold_information = "__threshold__".encode() + threshold_text.get().encode() + "__threshold__".encode()
            operation_information = "__operation__".encode() + pickle.dumps(operation_list) + "__operation__".encode()
            picture_information = "__information__".encode() + main_information + sub_information + desc_information + \
                                  threshold_information + operation_information + "__information__".encode()
            if debug:
                print(picture_information)
                print(path)
            if path is None or path == "":
                screen_text.set("请截图！")
                root.update()
                return 0
            add(path, picture_information)
            path = ""
            operation_list = []
            screen_text.set("已保存图片信息至数据库")
            root.update()
            return 0
        else:
            screen_text.set("未保存图片信息至数据库")
            return 0

    main_information = "__mainTask__".encode() + main_text.get().encode() + "__mainTask__".encode()
    sub_information = "__subTask__".encode() + subtask_text.get().encode() + "__subTask__".encode()
    desc_information = "__desc__".encode() + desc_text.get().encode() + "__desc__".encode()
    threshold_information = "__threshold__".encode() + threshold_text.get().encode() + "__threshold__".encode()
    operation_information = "__operation__".encode() + pickle.dumps(operation_list) + "__operation__".encode()
    picture_information = "__information__".encode() + main_information + sub_information + desc_information + \
                          threshold_information + operation_information + "__information__".encode()
    if debug:
        print(picture_information)
        print(path)
    if path is None or path == "":
        screen_text.set("请截图！")
        root.update()
        return 0
    add(path, picture_information)
    path = ""
    screen_text.set("已保存图片信息至数据库")
    root.update()


def read(file):
    if file is None or file == "":
        return 0
    f = open(file, 'rb')
    r = f.read()
    f.close()
    return r


def open_task():
    global operation_list
    global path
    global cut_img
    task_path = os.path.join(os.getcwd(), "img")
    task_path = os.path.join(task_path, main_text.get())
    task_path = os.path.join(task_path, subtask_text.get())
    file_path = filedialog.askopenfilename(title=u'选择图片', initialdir=(os.path.expanduser(task_path)))
    if debug:
        print(file_path)
    r = read(file_path)
    if r == 0:
        return 0
    if debug:
        print("信息长度：" + str(len(r.split(b"__information__"))))
    if len(r.split(b"__information__")) == 1:
        screen_text.set("图片没有存储任何信息，无法打开")
        return 0
    main_text.set(bytes.decode(r.split(b"__information__")[-2].split(b"__mainTask__")[1]))
    subtask_text.set(bytes.decode(r.split(b"__information__")[-2].split(b"__subTask__")[1]))
    desc_text.set(bytes.decode(r.split(b"__information__")[-2].split(b"__desc__")[1]))
    threshold_text.set(bytes.decode(r.split(b"__information__")[-2].split(b"__threshold__")[1]))
    operation_list = pickle.load(io.BytesIO(r.split(b"__information__")[-2].split(b"__operation__")[1]))
    path = file_path
    cut_img = cv2.imdecode(numpy.fromfile(file_path, dtype=numpy.uint8), -1)
    screen_text.set("图片已经打开了")
    root.update()
    if debug:
        for op in operation_list:
            print('\n'.join(['%s:%s' % item for item in op.__dict__.items()]) + "\n")


def show_operation():
    if len(operation_list) == 0:
        screen_text.set("没有任何操作存储在内存")
        return 0

    operation_root = tk.Toplevel()
    operation_root.title("操作列表")
    operation_root.geometry("+{0}+{1}".format(int(screen_width/2.2), int(screen_height/3)))
    row = 0
    column = 0

    for op in operation_list:
        id_text = tk.StringVar()
        operation_text_operation = tk.StringVar()
        translate_text_operation = tk.StringVar()
        delay_text_operation = tk.StringVar()
        drag_text_operation = tk.StringVar()
        input_text_operation = tk.StringVar()
        op_Frame = tk.Frame(operation_root)
        # 变量赋值
        operation_text_operation.set("请选择操作")
        translate_text_operation.set("无法进行操作")
        drag_text_operation.set("无法进行操作")
        input_text_operation.set("无法进行操作")
        delay_text_operation.set("无法进行操作")
        id_text.set(operation_list[column + row*5].operation_id)
        if isinstance(operation_list[column], Click):
            operation_text_operation.set("点击")
            translate_text_operation.set(operation_list[column].translate)
            delay_text_operation.set(operation_list[column].delay_time)
        if isinstance(operation_list[column], Drag):
            operation_text_operation.set("拖拽")
            drag_text_operation.set(operation_list[column].translate_pre + " " + operation_list[column].translate_behind)
            delay_text_operation.set(operation_list[column].delay_time)
        if isinstance(operation_list[column], Input):
            operation_text_operation.set("输入文本")
            input_text_operation.set(operation_list[column].text)
            delay_text_operation.set(operation_list[column].delay_time)
        op_Frame.update()
        # 组件
        id_Label = tk.Label(op_Frame, text="编号")
        id_Entry = tk.Entry(op_Frame, state='readonly', textvariable=id_text)
        operation_Label = tk.Label(op_Frame, text="操作")
        operation_Entry = tk.Entry(op_Frame, textvariable=operation_text_operation, state='readonly')

        translate_Label = tk.Label(op_Frame, text="点击坐标")
        translate_Entry = tk.Entry(op_Frame, textvariable=translate_text_operation, state='readonly')

        drag_Label = tk.Label(op_Frame, text="拖拽")
        drag_Entry = tk.Entry(op_Frame, textvariable=drag_text_operation, state='readonly')

        input_Label = tk.Label(op_Frame, text="输入文本")
        input_Entry = tk.Entry(op_Frame, textvariable=input_text_operation, state='readonly')

        delay_Label = tk.Label(op_Frame, text="延迟毫秒")
        delay_Entry = tk.Entry(op_Frame, textvariable=delay_text_operation, state='readonly')

        id_Label.grid(row=0, column=0, ipadx=5, ipady=5)
        id_Entry.grid(row=0, column=1, ipadx=5, ipady=5)
        operation_Label.grid(row=1, column=0, ipadx=5, ipady=5)
        operation_Entry.grid(row=1, column=1, ipadx=5, ipady=5)
        translate_Label.grid(row=2, column=0, ipadx=5, ipady=5)
        translate_Entry.grid(row=2, column=1, ipadx=5, ipady=5)
        drag_Label.grid(row=3, column=0, ipadx=5, ipady=5)
        drag_Entry.grid(row=3, column=1, ipadx=5, ipady=5)
        input_Label.grid(row=4, column=0, ipadx=5, ipady=5)
        input_Entry.grid(row=4, column=1, ipadx=5, ipady=5)
        delay_Label.grid(row=5, column=0, ipadx=5, ipady=5)
        delay_Entry.grid(row=5, column=1, ipadx=5, ipady=5)

        op_Frame.grid(row=row, column=column)
        column = column + 1
        if column >= 5:
            row = row + 1
            column = 0


def monitor():
    monitor_root = tk.Toplevel()
    monitor_root.title("鼠标监控")
    if debug:
        print("+{0}+{1}".format(screen_width - 250, 0))
    monitor_root.geometry("+{0}+{1}".format(screen_width - 250, 1))
    monitor_root.wm_attributes('-topmost', 1)
    monitor_Entry = tk.Entry(monitor_root, textvariable=monitor_text, state='readonly')
    monitor_Entry.pack()
    while 1:
        keyboard.wait('F2')
        if debug:
            print(PyMouse().position())
            monitor_text.set(str(PyMouse().position()))
        time.sleep(0.1)


def start_monitor():
    _thread.start_new_thread(monitor, ())


def zhuchun():
    text = "草稿本，可以联系我：\n电子邮箱：2590292@gmail.com"
    zhuchun_root = tk.Toplevel()
    zhuchun_root.title(text)
    monitor_Text = tk.Text(zhuchun_root)
    monitor_Text.pack()
    zhuchun_root.mainloop()


# ##基本信息框##
tools = tk.Frame(root)
# ##基本信息框##
operation_Frame = tk.Frame(root)
# # 创建组件

# 截图按钮
screen_Button = tk.Button(tools, text="截图", command=cut_thread)
# 截图信息
screen_text_Label = tk.Label(tools, textvariable=screen_text)
# 主任务名称
main_Label = tk.Label(tools, text="主任务名称")
main_text_Entry = tk.Entry(tools, textvariable=main_text)
# 子任务名称
subtask_Label = tk.Label(tools, text="子任务名称")
subtask_text_Entry = tk.Entry(tools, textvariable=subtask_text)
# 任务描述
desc_Label = tk.Label(tools, text="任务描述")
desc_text_Entry = tk.Entry(tools, textvariable=desc_text)
# 操作
# operation_Label = tk.Label(tools, text="操作")
# operation_values_Combobox = ttk.Combobox(tools, state='readonly', values=operation_values, width=17,
#                                          textvariable=operation_text)
# operation_values_Combobox.bind('<<ComboboxSelected>>', operation)
# # 布局组件
screen_Button.grid(row=0, column=0, ipadx=5, ipady=1)
screen_text_Label.grid(row=0, column=1)
main_Label.grid(row=1, column=0, ipadx=5, ipady=5)
main_text_Entry.grid(row=1, column=1, ipadx=10, ipady=1)
subtask_Label.grid(row=2, column=0, ipadx=5, ipady=5)
subtask_text_Entry.grid(row=2, column=1, ipadx=10, ipady=1)
desc_Label.grid(row=3, column=0, ipadx=5, ipady=5)
desc_text_Entry.grid(row=3, column=1, ipadx=10, ipady=1)

# delay_Label = tk.Label(operation_Frame, text="延迟(毫秒)")
# delay_text_Entry = tk.Entry(operation_Frame, textvariable=delay_text)
# delay_Label.grid(row=9, column=0, ipadx=5, ipady=5)
# delay_text_Entry.grid(row=9, column=1, ipadx=10, ipady=1)
threshold_Label = tk.Label(operation_Frame, text="识别阈值")
threshold_text_Entry = tk.Entry(operation_Frame, textvariable=threshold_text)
threshold_Label.grid(row=10, column=0, ipadx=5, ipady=5)
threshold_text_Entry.grid(row=10, column=1, ipadx=10, ipady=1)
next_button = tk.Button(operation_Frame, text="识别测试", command=next_set)
next_button.grid(row=11, column=0, ipadx=10, pady=10)
operation_button = tk.Button(operation_Frame, text="增加操作", command=add_task)
operation_button.grid(row=12, column=0, ipadx=10, pady=10)

init_button = tk.Button(operation_Frame, text="设置", command=set_windows)
init_button.grid(row=11, column=1, ipadx=80)

complete_button = tk.Button(operation_Frame, text="保存", command=complete)
complete_button.grid(row=12, column=1, ipadx=80)

open_button = tk.Button(operation_Frame, text="打开任务", command=open_task)
open_button.grid(row=13, column=0, ipadx=10, pady=10)

show_button = tk.Button(operation_Frame, text="查看", command=show_operation)
show_button.grid(row=13, column=1, ipadx=80)

monitor_button = tk.Button(operation_Frame, text="监控坐标", command=start_monitor)
monitor_button.grid(row=14, column=0, ipadx=10, pady=10)

zhuchun_button = tk.Button(operation_Frame, text="草稿", command=zhuchun)
zhuchun_button.grid(row=14, column=1, ipadx=80)

tools.pack(side=tk.TOP)
operation_Frame.pack()


if __name__ == '__main__':
    debug = True
    root.mainloop()
